--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_kumoi_ichirin_and_unzan = General:new(extension, "hy_kumoi_ichirin_and_unzan", "jin_k", 4, 4, General.Female)
    local double_servant = fk.CreateSkill {
        name = "double_servant",
        tags = {
            Skill.Switch,
        },
    }
    double_servant:addEffect("active", {
        anim_type = "switch",
        times = function(self, player)
            return 2 - player:usedSkillTimes(double_servant.name, Player.HistoryPhase)
        end,
        card_filter = Util.FalseFunc,
        target_filter = Util.FalseFunc,
        can_use = function(self, player)
            return player:hasSkill(double_servant.name) and player:usedSkillTimes(double_servant.name, Player.HistoryPhase) < 2 and not player:isKongcheng()
        end,
        prompt = function(self, player, selected_cards, selected_targets)
            local state = player:getSwitchSkillState(double_servant.name)
            local cards = player:getCardIds("h")
            local red = 0
            local black = 0
            for _, id in ipairs(cards) do
                if Fk:getCardById(id).color == Card.Red then
                    red = red + 1
                else
                    black = black + 1
                end
            end
            if state == fk.SwitchYang then
                if red < black then
                    return "double_servant_iron_chain"
                elseif red > black then
                    return "double_servant_fire__slash"
                end
            else
                if red < black then
                    return "double_servant_draw"
                elseif red > black then
                    return "double_servant_recover"
                end
            end
            return "double_servant_prompt"
        end,
        on_use = function(self, room, cardUseEvent)
            local player = cardUseEvent.from
            local state = player:getSwitchSkillState(double_servant.name, true)
            local red = 0
            local black = 0
            player:showCards(player:getCardIds("h"))
            local cards = player:getCardIds("h")
            for _, id in ipairs(cards) do
                if Fk:getCardById(id).color == Card.Red then
                    red = red + 1
                else
                    black = black + 1
                end
            end
            if state == fk.SwitchYang then
                if red < black then
                    local success, use = room:askToUseActiveSkill(player, {
                        skill_name = "anger_eyes",
                        prompt = "double_servant_iron_chain"
                    })
                    if success and use then
                        local card = Fk:cloneCard("iron_chain")
                        card:addSubcards(use.cards)
                        table.insertIfNeed(card.skillNames, "double_servant")
                        room:useCard({
                            card = card,
                            tos = use.targets,
                            from = player,
                        })
                    end
                elseif red > black then
                    local success, use = room:askToUseActiveSkill(player, {
                        skill_name = "anger_punch",
                        prompt = "double_servant_fire__slash",
                        cancelable = true,
                        extra_data = { bypass_times = true }
                    })
                    if success and use then
                        local card = Fk:cloneCard("fire__slash")
                        card:addSubcards(use.cards)
                        table.insertIfNeed(card.skillNames, "double_servant")
                        room:useCard({
                            card = card,
                            tos = use.targets,
                            from = player,
                            extraUse = true,
                        })
                    end
                end
            else
                if red < black then
                    if not player.dead and room:askToSkillInvoke(player, {
                            skill_name = double_servant.name,
                            prompt = "double_servant_draw"
                        }) then
                        room:drawCards(player, 2, double_servant.name)
                    end
                elseif red > black then
                    local targets = room:askToChoosePlayers(player, {
                        targets = table.filter(room.alive_players, function(t)
                            return t:isWounded() and player ~= t
                        end),
                        min_num = 1,
                        max_num = 1,
                        prompt = "double_servant_recover",
                        skill_name = double_servant.name,
                    })
                    for _, t in ipairs(targets) do
                        room:recover({
                            who = t,
                            num = 1,
                            recoverBy = player,
                            skillName = double_servant.name
                        })
                    end
                end
            end
            local recast = room:askToCards(player, {
                min_num = 1,
                max_num = 1,
                skill_name = double_servant.name,
                pattern = ".|.|.|hand",
                prompt = "double_servant_recast"
            })
            if type(recast) == "number" then
                recast = { recast }
            end
            if #recast > 0 then
                room:recastCard(recast, player, double_servant.name)
            end
        end
    })
    local anger_punch = fk.CreateSkill {
        name = "anger_punch",
    }
    anger_punch:addEffect("viewas", {
        mute_card = false,
        anim_type = "offensive",
        pattern = "fire__slash",
        card_filter = function(self, player, to_select, selected)
            local card = Fk:cloneCard("fire__slash", Fk:getCardById(to_select).suit, Fk:getCardById(to_select).number)
            return #selected == 0 and table.contains(player:getCardIds("h"), to_select) and player:canUse(card, { bypass_times = true })
        end,
        prompt = function(self, player, selected_cards, selected)
            return "double_servant_fire__slash"
        end,
        view_as = function(self, player, cards)
            if #cards ~= 1 then
                return
            end
            local origin = Fk:getCardById(cards[1])
            local card = Fk:cloneCard("fire__slash", origin.suit, origin.number)
            card:addSubcard(origin)
            table.insertIfNeed(card.skillNames, "double_servant")
            return card
        end,
        before_use = function(self, player, use)
            use.extraUse = true
        end
    })
    local anger_eyes = fk.CreateSkill {
        name = "anger_eyes",
    }
    anger_eyes:addEffect("viewas", {
        mute_card = false,
        anim_type = "offensive",
        pattern = "iron_chain",
        card_filter = function (self, player, to_select, selected)
            local card = Fk:cloneCard("iron_chain", Fk:getCardById(to_select).suit, Fk:getCardById(to_select).number)
            return #selected == 0 and table.contains(Self.player_cards[Player.Hand], to_select) and Self:canUse(card)
        end,
        prompt = function (self, player, selected_cards, selected)
            return "double_servant_iron_chain"
        end,
        view_as = function (self, player, cards)
            if #cards ~= 1 then
                return
            end
            local origin = Fk:getCardById(cards[1])
            local card = Fk:cloneCard("iron_chain", origin.suit, origin.number)
            card:addSubcard(origin)
            table.insertIfNeed(card.skillNames, "double_servant")
            return card
        end,
    })
    local fight_together = fk.CreateSkill {
        name = "fight_together",
    }
    fight_together:addEffect(fk.Damaged, {
        can_trigger = function(self, event, target, player)
            return player:hasSkill(fight_together.name) and target == player and player:usedSkillTimes(fight_together.name, Player.HistoryTurn) == 0
        end,
        on_use = function(self, event, target, player)
            local room = player.room
            if player:getMark(MarkEnum.SwithSkillPreName .. "double_servant") == 1 then
                room:setPlayerMark(player, MarkEnum.SwithSkillPreName .. "double_servant", 0)
                room:doBroadcastNotify("UpdateQuestSkillUI", {
                    player.id,
                    "double_servant",
                    0,
                })
            else
                room:setPlayerMark(player, MarkEnum.SwithSkillPreName .. "double_servant", 1)
                room:doBroadcastNotify("UpdateQuestSkillUI", {
                    player.id,
                    "double_servant",
                    1,
                })
            end
        end
    })
    fight_together:addEffect(fk.Damage, {
        can_trigger = function(self, event, target, player)
            return player:hasSkill(fight_together.name) and target == player and player:usedSkillTimes(fight_together.name, Player.HistoryTurn) == 0
        end,
        on_use = function(self, event, target, player)
            local room = player.room
            if player:getMark(MarkEnum.SwithSkillPreName .. "double_servant") == 1 then
                room:setPlayerMark(player, MarkEnum.SwithSkillPreName .. "double_servant", 0)
                room:doBroadcastNotify("UpdateQuestSkillUI", {
                    player.id,
                    "double_servant",
                    0,
                })
            else
                room:setPlayerMark(player, MarkEnum.SwithSkillPreName .. "double_servant", 1)
                room:doBroadcastNotify("UpdateQuestSkillUI", {
                    player.id,
                    "double_servant",
                    1,
                })
            end
        end
    })
    extension:loadSkillSkels { double_servant, anger_punch, anger_eyes, fight_together }
    hy_kumoi_ichirin_and_unzan:addSkill("double_servant")
    hy_kumoi_ichirin_and_unzan:addSkill("fight_together")
    Fk:loadTranslationTable {
        ["hy_kumoi_ichirin_and_unzan"] = "云居一轮",
        ["#hy_kumoi_ichirin_and_unzan"] = "文武双打",
        ["illustrator:hy_kumoi_ichirin_and_unzan"] = "サニーサイド",
        ["designer:hy_kumoi_ichirin_and_unzan"] = "黑曜人形",
        ["cv:hy_kumoi_ichirin_and_unzan"] = "",

        ["double_servant"] = "双役",
        [":double_servant"] = "转换技，出牌阶段限两次，你可以展示所有手牌，若其中红色牌较少/较多，阳：你可以将一张手牌当作【铁索连环】/不计次数且无次数限制的火【杀】使用，阴：你可以摸两张牌/令一名其他角色回复1点体力。然后你可以重铸一张手牌。",
        ["double_servant_draw"] = "双役：你可以摸2张牌",
        ["double_servant_recover"] = "双役：你可以令1名其他角色回复1点体力",
        ["double_servant_iron_chain"] = "双役：你可以将一张手牌当作【铁索连环】使用",
        ["double_servant_fire__slash"] = "双役：你可以将一张手牌当作火【杀】使用",
        ["double_servant_recast"] = "双役：你可以重铸一张手牌",
        ["double_servant_prompt"] = "双役：你可以展示所有手牌",
        ["anger_eyes"] = "双役",
        ["anger_punch"] = "双役",

        ["fight_together"] = "共斗",
        [":fight_together"] = "每回合限一次,在你造成或受到伤害后，你可以将“双役”转换至另一状态。",
    }
end
